﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mrkz.ImageManipulation.SpatialFiltering
{
    public class MeanFilterKernel :SpatialFilterKernel
    {
        public MeanFilterKernel(int size)
            : base(size)
        {
            for (int i = 0; i < _size; i++)
                for (int j = 0; j < _size; j++)
                    _kernel[i, j] = 1;

            NormalizeKernel();
        }
    }

    public class IdentityFilterKernel : SpatialFilterKernel
    {
        public IdentityFilterKernel(int size)
            : base(size)
        {
            base.setKernelElementWithRelativePosition(1, 0, 0);
        }
    }

    public class MotionBlur5 : SpatialFilterKernel
    {
        public MotionBlur5()
            : base(5)
        {
            setKernelElementWithRelativePosition(5, 0, 0);

            setKernelElementWithRelativePosition(5, -1, -1);
            setKernelElementWithRelativePosition(5, 1, 1);

            setKernelElementWithRelativePosition(5, -2, -2);
            setKernelElementWithRelativePosition(5, 2, 2);

            setKernelElementWithRelativePosition(5, 1, -1);
            setKernelElementWithRelativePosition(5, -1, 1);

            setKernelElementWithRelativePosition(5, 2, -2);
            setKernelElementWithRelativePosition(5, -2, 2);

            NormalizeKernel();
        }

        public override SpatialFilterKernel AdjustEffectIntensity (float factor)
        {
            MotionBlur5 b = new MotionBlur5();

            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(2, 2) * factor * factor, 2, 2);
            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(-2, -2) * factor * factor, -2, -2);

            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(-1, -1) * factor, -1, -1);
            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(1, 1) * factor, 1, 1);
            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(1, -1) * factor, 1, -1);
            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(-1, 1) * factor, -1, 1);

            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(2, -2) * factor * factor, 2, -2);
            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(-2, 2) * factor * factor, -2, 2);

            b.setKernelElementWithRelativePosition(getKernelElementWithRelativePosition(0, 0), 0, 0);

            b.NormalizeKernel();

            return b;

        }
    }

    public class IdiotFilter:SpatialFilterKernel
    {
        public IdiotFilter()
            : base(5)
        {
            setKernelElementWithRelativePosition(5, 0, 0);

            setKernelElementWithRelativePosition(5, 2, 2);
            setKernelElementWithRelativePosition(5, -2, -2);

            setKernelElementWithRelativePosition(5, -2, 2);
            setKernelElementWithRelativePosition(5, 2, -2);
            
            NormalizeKernel();
        }
    }
}
